package cn.edu.nwsuaf.examcenter.pojo;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * ExamContent entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "exam_content", catalog = "exam")
public class ExamContent implements java.io.Serializable {

	// Fields

	private ExamContentId id;
	private ExamPaperInfo examPaperInfo;
	private ExamItem examItem;
	private Float examItemScore;
	private Set<StudentExamAnswer> studentExamAnswers = new HashSet<StudentExamAnswer>(
			0);

	// Constructors

	/** default constructor */
	public ExamContent() {
	}

	/** minimal constructor */
	public ExamContent(ExamContentId id, ExamPaperInfo examPaperInfo,
			ExamItem examItem, Float examItemScore) {
		this.id = id;
		this.examPaperInfo = examPaperInfo;
		this.examItem = examItem;
		this.examItemScore = examItemScore;
	}

	/** full constructor */
	public ExamContent(ExamContentId id, ExamPaperInfo examPaperInfo,
			ExamItem examItem, Float examItemScore,
			Set<StudentExamAnswer> studentExamAnswers) {
		this.id = id;
		this.examPaperInfo = examPaperInfo;
		this.examItem = examItem;
		this.examItemScore = examItemScore;
		this.studentExamAnswers = studentExamAnswers;
	}

	// Property accessors
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "examPaperNo", column = @Column(name = "exam_paper_no", nullable = false, length = 50)),
			@AttributeOverride(name = "examItemNo", column = @Column(name = "exam_item_no", nullable = false, length = 50)) })
	public ExamContentId getId() {
		return this.id;
	}

	public void setId(ExamContentId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "exam_paper_no", nullable = false, insertable = false, updatable = false)
	public ExamPaperInfo getExamPaperInfo() {
		return this.examPaperInfo;
	}

	public void setExamPaperInfo(ExamPaperInfo examPaperInfo) {
		this.examPaperInfo = examPaperInfo;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "exam_item_no", nullable = false, insertable = false, updatable = false)
	public ExamItem getExamItem() {
		return this.examItem;
	}

	public void setExamItem(ExamItem examItem) {
		this.examItem = examItem;
	}

	@Column(name = "exam_item_score", nullable = false, precision = 12, scale = 0)
	public Float getExamItemScore() {
		return this.examItemScore;
	}

	public void setExamItemScore(Float examItemScore) {
		this.examItemScore = examItemScore;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "examContent")
	public Set<StudentExamAnswer> getStudentExamAnswers() {
		return this.studentExamAnswers;
	}

	public void setStudentExamAnswers(Set<StudentExamAnswer> studentExamAnswers) {
		this.studentExamAnswers = studentExamAnswers;
	}

}